import {Helpers, Plugin} from "postcss";
import Result from "postcss/lib/result";
import Declaration from "postcss/lib/declaration";
import Rule from "postcss/lib/rule";
import AtRule from "postcss/lib/at-rule";

export default function deepSupport(): Plugin {
    return {
        postcssPlugin: "deepSupport",
        prepare(result: Result) {
            // 这里可以放一些公共的逻辑
            return {
                // decl：具体的样式，比如： padding: 5px;
                Declaration(decl: Declaration, helper: Helpers) {
                },
                // rule：选择器开头的规则，比如：ul li
                Rule(rule: Rule, helper: Helpers) {
                    if (rule.selector.includes("/deep/")) {
                        console.log(555)
                        rule.selector = rule.selector.replace(/\/deep\//g, '::v-deep')
                    }
                },
                // 以 @ 开头的规则 比如： @media screen and (min-width: 480px)
                AtRule(atRule: AtRule, helper: Helpers) {
                }
            }
        }
    }
}
